﻿using System.Collections.Generic;
using System.Linq;
using WholesaleOnline.Model;

namespace WholesaleOnline.Controller.Extension
{
    public static class ProductExtensionMethod
    {
        public static IEnumerable<dynamic> ConvertToJsonModel(this IEnumerable<WoProduct> products)
        {
            return products.Select(product => new
            {
                id = product.Id,
                name = product.Name,
                fullPrice = string.Format("{0}/{1}", product.Price, product.Unit.Name),
                unit = product.Unit.Name,
                pic = product.Img,
                seller = product.Seller.Name,
                sn = product.Sn,
                desc = product.Description,
                bigUnits = product.BigUnits.Select(u => new
                {
                    id = u.Unit.Id,
                    name = u.Unit.Name,
                    count = u.Count
                })
            }); 
        }
    }
}
